package com.gmgx.controller;


import com.gmgx.dao.IStudentDao;
import com.gmgx.entity.Student;
import com.gmgx.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("teacher")
@Api(value = "teacher", description = "教师的控制类")
public class TeacherController {
    @Autowired
    private IStudentService studentService;

    // 如果实现了前后端分离，后台（SSM工程）返回不再是jsp页面，而是 json数据
    // restFul 风格 设置  约定 GET查询  POST 添加  PUT 更新 DELETE  删除
    @RequestMapping(value = "queryAllStudent", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询全部学生", httpMethod = "GET")
    public List<Student> queryAllStudent(){
        return studentService.queryAllStudent();
    }

    @RequestMapping(value = "addStudent", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加学生", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sno", value = "学号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sname", value = "姓名", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "query")
    })
    public boolean addStudent(Student student){
        return studentService.addStudent(student);
    }

    @RequestMapping(value = "deleteStudentBySno", method = RequestMethod.DELETE)
    @ResponseBody
    @ApiOperation(value = "删除学生", httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sno", value = "学号", required = true, dataType = "int", paramType = "query")// 注意：paramType不写，测试会报错
    })
    public boolean deleteStudentBySno(Integer sno){
        System.out.println(sno);
        return studentService.deleteStudentBySno(sno);
    }

    @RequestMapping(value = "modifyStudent", method = RequestMethod.PUT)
    @ResponseBody
    @ApiOperation(value = "修改学生", httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sno", value = "学号", required = false, dataType = "int", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "sname", value = "姓名", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "query")
    })
    public boolean modifyStudent(Student student){
        return studentService.modifyStudent(student);
    }
}
